<?php
/**
 * 前台单页
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: SingleController.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Home\Controller;
class SingleController extends CommonController{
    private $PageModel;
    private $Page;
    public function _initialize() {
        parent::_initialize();
        $item = I("get.item", NULL);
        if(!$item){
            $this->error("对不起，你输入的参数有误！");
        }
        $this->PageModel = D("Page");
        $where = array();
        if(C("HOME_LANG_SWITCH_ON")){
            $lang = I("get.l", "zh-cn");
            $lang = isset($lang) ? trim($lang) :(cookie('think_language') ? cookie('think_language') : 'zh-cn');//语言标识
            $lang = TagCheckLang($lang);
            $where['lang'] = $lang;
        }
        $this->Page = $this->PageModel->where($where)->getByNid($item);
        
        $data = array();
        $data['title'] = $this->Page['title'];
        if(!empty($this->Page['keywords'])){
            $data['keywords'] = $this->Page['keywords'];
        }
        if(!empty($this->Page['description'])){
            $data['description'] = $this->Page['description'];
        }
        
        $data['body'] = htmlspecialchars_decode($this->Page['body']);
        $this->assign($data);
    }
    
    public function index() {
        $templateFile = T($this->Page['template']);
        if(!file_exists($templateFile)){
            $templateFile = T("index");
        }
        $this->display($templateFile);
    }
}
